/*
 * HttpImpl.h
 *
 *  Created on: 2012/02/05
 *      Author: takedanaoki
 */

#ifndef INCLUDED_NTENGINE_NET_HTTPIMPL_H
#define INCLUDED_NTENGINE_NET_HTTPIMPL_H

#include "NTEngine/Net/Http.h"
#include "NTEngine/Base/ReferenceCounter.h"

namespace NTEngine {
namespace Net {

class Http::Impl : public ReferenceCounter {
public:
	Impl( unsigned id ) : mId( id ), mBuffer( 0 ), mSize( 0 ), mCode( 0 ), mIsFinished( false ), mIsError( false ) {
	}

	~Impl() {
		SAFE_DELETE_ARRAY( mBuffer );
	}

	unsigned id() const {
		return mId;
	}

	bool isFinished() const {
		return mIsFinished;
	}

	bool isError() const {
		return mIsError;
	}

	int responseCode() const {
		return mCode;
	}

	const char* responseBuffer() const {
		return mBuffer;
	}

	int responseSize() const {
		return mSize;
	}

	// 渡されるバッファは管理を譲渡される
	void set( char* buf, int size, int code ) {
		ASSERT( !mIsFinished );
		mBuffer = buf;
		mSize = size;
		mCode = code;
		if ( ( mBuffer == 0 ) || ( size > 0 ) ) {
			mIsError = true;
		}
		mIsFinished = true;
	}

	void setError() {
		mIsFinished = mIsError = true;
	}

	const unsigned mId;
	char* mBuffer;
	int mSize;
	int mCode;
	bool mIsFinished;
	bool mIsError;
};

} // namespace Net
} // namespace NTEngine

#endif // INCLUDED_NTENGINE_NET_HTTPIMPL_H
